package com.letv.android.client.view;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.letv.ads.util.LogInfo;
import com.letv.android.young.client.R;

/**
 * Created by zhanglibin on 2015/1/14.
 */
public class BaseNetChangeLayer implements NetChangeLayer {
    private View netRoot;
    private View net_change_text1;
    private Button net_change_continue;
    private ViewGroup parent;
    private boolean bind;

    private ImageView net_top_back;
//    private ImageView net_full_half;
    private TextView net_top_title;
    private ImageView net_top_back_r;
    private TextView net_top_title_r;
    private View net_top_layout, net_top_layout_r;

    public BaseNetChangeLayer(Context context, ViewGroup parent) {
        if(context == null || parent == null) {
            throw new RuntimeException("context or parent cann't be null");
        }
        this.parent = parent;
        netRoot = LayoutInflater.from(context).inflate(R.layout.letv_net_change_layout, null ,false);
        if(parent instanceof RelativeLayout) {
            netRoot.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
        }
        parent.addView(netRoot);
        if(parent instanceof AbsListView) {
            parent.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.MATCH_PARENT));
        }
        LogInfo.log("3_g", getClass().getSimpleName() + "--------------addView netRoot = " + netRoot + " , parent = " + parent);
        bind = true;
        net_change_text1 = netRoot.findViewById(R.id.net_change_text1);
        net_change_continue = (Button) netRoot.findViewById(R.id.net_change_continue);
        net_top_back = (ImageView) netRoot.findViewById(R.id.net_top_back);
//        net_full_half = (ImageView) netRoot.findViewById(R.id.net_full_half);
        net_top_title = (TextView) netRoot.findViewById(R.id.net_top_title);
        net_top_back_r = (ImageView) netRoot.findViewById(R.id.net_top_back_r);
        net_top_title_r = (TextView) netRoot.findViewById(R.id.net_top_title_r);
        net_top_layout = netRoot.findViewById(R.id.net_top_layout);
        net_top_layout_r = netRoot.findViewById(R.id.net_top_r_layout);
    }

    @Override
    public void showBlack() {
        net_change_text1.setVisibility(View.GONE);
        net_change_continue.setVisibility(View.GONE);
    }

    @Override
    public void show3gAlert(View.OnClickListener l) {
        net_change_text1.setVisibility(View.VISIBLE);
        net_change_continue.setVisibility(View.VISIBLE);
        if(l != null) {
            net_change_continue.setOnClickListener(l);
        }
    }

    @Override
    public void hide() {
        if(bind) {
            parent.removeView(netRoot);
            LogInfo.log("3_g", "hide");
            netRoot = null;
            bind = false;
        }
    }

    public void setBackListener(View.OnClickListener listener) {
        if(listener != null) {
            net_top_back.setOnClickListener(listener);
        }
    }

    public void setFullHalfListener(View.OnClickListener listener) {
        if(listener != null) {
//            net_full_half.setOnClickListener(listener);
        }
    }
    
    //直播大厅标题和箭头靠右
    public void setTopRight(){
    	net_top_layout.setVisibility(View.GONE);
    	net_top_layout_r.setVisibility(View.VISIBLE);
    }
    
    //直播大厅标题靠右
    public void setTopTitleR(String text){
    	net_top_title_r.setText(TextUtils.isEmpty(text) ? "" : text);
    }
    
    public void setBackRightListener(View.OnClickListener listener) {
        if(listener != null) {
            net_top_back_r.setOnClickListener(listener);
        }
    }
    
    public void setTopTitle(String text) {
        net_top_title.setText(TextUtils.isEmpty(text) ? "" : text);
    }

    public void setHalfToIcon() {
//        net_full_half.setImageResource(R.drawable.letv_half_selecter);
    }

    public void setHalfIConVisible(boolean isVisible){
    	if(isVisible){
//    		net_full_half.setVisibility(View.VISIBLE);
    	}else{
//    		net_full_half.setVisibility(View.GONE);
    	}
    }
    
    public void setSize(int height, int width) {
        netRoot.getLayoutParams().width = width;
        netRoot.getLayoutParams().height = height;
    }

    public void hideController() {
        net_top_back.setVisibility(View.GONE);
//        net_full_half.setVisibility(View.GONE);
        net_top_title.setVisibility(View.GONE);
    }
}
